package com.cljz.makepassenger.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.cljz.makepassenger.base.App;
import com.cljz.makepassenger.R;
import com.cljz.makepassenger.base.BaseActivity;
import com.cljz.makepassenger.base.Constant;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.cache.SharedPref;
import cn.droidlover.xdroidmvp.router.Router;

/**
 * Created by apple on 2017/3/31.
 */

public class SplashActivity extends BaseActivity {
    @BindView(R.id.iv_launch)
    ImageView ivLaunch;

    @Override
    public void initData(Bundle savedInstanceState) {
        ivLaunch.setVisibility(View.GONE);
        ivLaunch.postDelayed(new Runnable() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ivLaunch.setVisibility(View.VISIBLE);
                    }
                });
            }
        }, 1000);
        //这是一种可以创建多线程消息的函数
        ivLaunch.postDelayed(new Runnable() {
            @Override
            public void run() {
                judgeTheFirstTime();
            }
        }, 3000);
    }

    private void judgeTheFirstTime() {
        if (SharedPref.getInstance(App.getInstance()).getBoolean(Constant.FIRST_OPEN, true)) {
            Router.newIntent((Activity) App.getInstance()).to(WelcomeGuideActivity.class).data(new Bundle()).launch();
            finish();
        } else {
            if ("".equals(SharedPref.getInstance(App.getInstance()).getString(Constant.TOKEN, ""))) {
                Router.newIntent((Activity) App.getInstance()).to(LoginActivity.class).data(new Bundle()).launch();
                Router.pop(this);
            } else {
//                Router.newIntent((Activity) App.getInstance())
//                        .to(GroupListActivity.class)
//                        .data(new Bundle())
//                        .launch();
                Router.newIntent((Activity) App.getInstance())
                        .to(MainActivity.class)
                        .data(new Bundle())
                        .launch();
                Router.pop(this);
            }
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_launch;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    protected void setScreen() {
        //WindowManager是Android中一个重要的服务（Service ）。WindowManager Service 是全局的，是唯一的
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        //窗口显示时，隐藏所有的屏幕装饰（例如状态条）。使窗口占用整个显示区域。
        lp.flags = (WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setAttributes(lp);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

    @Override
    protected void initPermission() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
